﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoMapper;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.Resolvers.SpecializedResolvers;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using IConfiguration = Castle.Core.Configuration.IConfiguration;

namespace Web.Installers
{
    public class AutoMapperInstaller : IWindsorInstaller
    {
        public class ArrayFacility : IFacility
        {
            public void Init(IKernel kernel, IConfiguration facilityConfig)
            {
                kernel.Resolver.AddSubResolver(new ArrayResolver(kernel));
            }

            public void Terminate() { }
        }

        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                AllTypes.FromThisAssembly().BasedOn<Profile>().WithServiceBase());
            container.Register(
                AllTypes.FromThisAssembly().BasedOn<IValueResolver>().WithServiceDefaultInterfaces());
        }

        private static BasedOnDescriptor FindProfiles()
        {
            return AllTypes
                .FromThisAssembly()
                .BasedOn<Profile>();
        }
    }
}